<?php
function get_document_kids_html($document)
{
  if(!count($document->getChildren()))
    return '';
  $html = '<ul>';
  foreach($document->getChildren() as $one_document) {
    $html .= '<li>';
      $html .= '<a href="'.$one_document->getUri().'">'.$one_document->getTitle().'</a>';
      $html .= get_document_kids_html($one_document);
    $html .= '</li>';
  }
  $html .= '</ul>';
  return $html;
}

echo get_document_kids_html($document);
  
?>
 